import React from 'react';
import {Form, Row, Col, Button, DatePicker, message ,Divider ,Input,Popconfirm } from 'antd';
// import { Link } from 'react-router-dom'
import {sessionManager} from '../../utils/sessionStorage';
// import SCModal from '../../components/pickCity/SCModal'
import {injectIntl} from 'react-intl';
import Grid from '../../components/table/grid';
import StatisticsBox from '../../components/box/statistics';
import axios from 'axios';

const FormItem = Form.Item;
const createForm = Form.create;
const {RangePicker} = DatePicker;


class ecard extends React.Component {
    constructor(props) {
        super(props);
        this.dateFormat='YYYY-MM-DD HH:mm:ss';
        this.common = this.props.intl.messages.common;
        this.columns = [
            {
                title: '卡号',
                dataIndex: 'no',
                key: 'no',
            },
            {
                title: '手机号',
                dataIndex: 'phone',
                key: 'phone',
            },
            {
                title: '用户名',
                dataIndex: 'account',
                key: 'account',
            },
            {
                title: '姓名',
                dataIndex: 'name',
                key: 'name',
            },
            {
                title: '信息',
                dataIndex: 'info',
                key: 'info',
                className:"SC-col-dots",
            },
            {
                title: '创建时间',
                dataIndex: 'createTime',
                key: 'createTime',
            },
        ];
        this.state = {
            refresh:0,
            boxParams:[],
            params:{
                companyId:sessionManager.get('companyInfo').id
            }
        }
    }

    componentDidMount(){
        
    }

    transformData=(data)=>{
        this.setState({
            boxParams:[
                {
                    num:data.summary?data.summary.cnt:0,
                    desc:"短信总计"
                },
            ]
        })
        return data.list
    }

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((errors, values) => {
            if (!!errors) {
                console.log('Errors in form!!!');
                return;
            }
            this.setState({
                params:values.Time&&values.Time.length>0?Object.assign(this.state.params,{startDate:values.Time[0].format(this.dateFormat),endDate:values.Time[1].format(this.dateFormat)}):{},
                refresh:this.state.refresh+1
            })
        });
    }


    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <div>
                <form form={this.props.form}>
                    <Row gutter={8}>
                        <Col xl={8} xxl={5}>
                            <FormItem>
								{getFieldDecorator('Time',
								)(
									<RangePicker format={this.dateFormat} />
								)}
							</FormItem>
                        </Col>
                        <Col span={4}>
                            <FormItem>
                               <Button type={'primary'} onClick={this.handleSubmit}>确定</Button>
                            </FormItem>
                        </Col>
                    </Row>
                </form>
                <StatisticsBox params={this.state.boxParams}/>
                <Grid transformData={this.transformData} params={this.state.params} url="/api/corp/sms/qry" columns={this.columns} refresh={this.state.refresh}/>
            </div>
        )
    }
}

ecard = createForm()(ecard);
export default injectIntl(ecard)
